package remato.client.view.editor.properties;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;

import remato.client.model.ClientModelItem;
import remato.client.view.editor.AbstractFormPage;
import remato.client.view.editor.IModelFormPart;
import remato.client.view.facade.IModelChangeListener;
import remato.client.view.facade.IModelUpdateListener;

/**
 * @author petterei
 *
 * @version $Id: PropertiesFormPage.java,v 1.1 2006-01-23 19:58:36 petterei Exp $
 */

public class PropertiesFormPage extends AbstractFormPage implements IModelUpdateListener, IModelChangeListener {
	public final static String PAGE_ID = "modelProperties" ;
	public final static String PAGE_TITLE = "Properties" ;
	
	private List<IModelFormPart> formParts = new ArrayList<IModelFormPart>();

	public PropertiesFormPage(FormEditor editor) {
		super(editor, PAGE_ID, PAGE_TITLE);
	}
	/**
	 * @see org.eclipse.ui.forms.editor.FormPage#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createPartControl(Composite parent) {
		super.createPartControl(parent);
	}
	/**
	 * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
	 */
	@Override
	protected void createFormContent(IManagedForm managedForm) {
		super.createFormContent(managedForm);  // does nothing
		updateText();
		Composite body = managedForm.getForm().getBody();
//		FormLayout bodyLayout = new FormLayout();
		FillLayout bodyLayout = new FillLayout(SWT.VERTICAL);
		body.setLayout(bodyLayout);
		formParts = ((ClientModelItem)getModelItem()).getPropertiesFormParts(this, getManagedForm());
		Composite previous = null;
		FillLayout layout = null;
		for (IModelFormPart part : formParts) {
//			FormData data = new FormData();
//			data.left = new FormAttachment(0,5);
//			if (null == previous) {
//				data.top = new FormAttachment(0,0);
//			} else {
//				data.top = new FormAttachment(previous, 10);
//			}
//			data.right = new FormAttachment(100, -5);
			previous = part.getSection().getParent();
//			previous.setLayoutData(data);
			layout = new FillLayout();
			previous.setLayout(layout);
			getManagedForm().addPart(part);
		}
		managedForm.reflow(true);
	}
	
}
